/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package btnhom;

import java.io.*;
import java.sql.Connection;
import oracle.jdbc.OracleResultSet;
import oracle.jdbc.OraclePreparedStatement;
import conn.JavaConnectDb;
import javax.swing.JOptionPane;
import java.awt.Toolkit;
import java.awt.event.WindowEvent;
import java.lang.*;
/**
 *
 * @author nhung
 */
public class Loainen {
    private String ma_ln;
    private String m_ta;
    
    Connection conn;
    OraclePreparedStatement pst;
    OracleResultSet rs;
    
    public String getMa_ln() {
        return ma_ln;
    }

    public void setMaloai_nen(String ma_ln) {
        this.ma_ln = ma_ln;
    }

    public String getMota() {
        return m_ta;
    }

    public void setMota(String m_ta) {
        this.m_ta = m_ta;
    }
    public OracleResultSet selectLoaiNen(){
        conn = JavaConnectDb.ConnectDb();
        try{
            String sql = "select * from loainen_tdc";
            pst=(OraclePreparedStatement) conn.prepareStatement(sql);
            rs = (OracleResultSet) pst.executeQuery();
            
         }catch(Exception e){
            JOptionPane.showMessageDialog(null, "Khong the ket noi server");
        }
        return rs;
    } 
    public void insertLoaiNen(String maln, String mta)
    {
        conn = JavaConnectDb.ConnectDb();
        try{
            String sql = "insert into loainen_tdc(maloai_nen, mota) values(?,?)";
            pst=(OraclePreparedStatement) conn.prepareStatement(sql);
            pst.setString(1, maln);
            pst.setString(2, mta);
            pst.executeQuery();
                    
         }catch(Exception e){
            JOptionPane.showMessageDialog(null, "Khong the ket noi CSDL");
        }finally {
        try { conn.close(); } catch (Exception e) { /* ignored */ }
        }
    }
    public void updateLoaiNen(String maln, String mta)
    {
        conn = JavaConnectDb.ConnectDb();
        try{
            String sql = "update loainen_tdc set mota=? where maloai_nen=?";
            pst=(OraclePreparedStatement) conn.prepareStatement(sql);
            pst.setString(2, maln);
            pst.setString(1, mta);
            pst.executeQuery();
            JOptionPane.showMessageDialog(null, "Cap nhat thanh cong");        
         }catch(Exception e){
            JOptionPane.showMessageDialog(null, "Cap nhat khong thanh cong");
        } finally {
        try { conn.close(); } catch (Exception e) { /* ignored */ }
        }
    }
    public void deleteLoaiNen(String maln)
    {
        conn = JavaConnectDb.ConnectDb();
        try{
            String sql = "delete from loainen_tdc where maloai_nen=?";
            pst=(OraclePreparedStatement) conn.prepareStatement(sql);
            pst.setString(1, maln);
            pst.executeQuery();
            JOptionPane.showMessageDialog(null, "Xoa thanh cong");        
         }catch(Exception e){
            JOptionPane.showMessageDialog(null, "Xoa khong thanh cong");
        } finally {
        try { conn.close(); } catch (Exception e) { /* ignored */ }
        }
    }
}
